/**
 * 
 */
function setAllMap(map) {
  for (var i = 0; i < markers.length; i++) {
    markers[i].setMap(map);
  }
}

// Removes the markers from the map, but keeps them in the array.
function clearMarkers() {
  setAllMap(null);
}

function dajVozilo()
{
	clearMarkers();
	var req = createRequest(); // defined above
	//Create the callback:
	req.onreadystatechange = function() {
	if (req.readyState != 4) return; // Not there yet
	if (req.status != 200) {
	 // Handle request failure here...
	 return;
	}
	// Request successful, read the response
	var respXML= req.responseXML;
	var rID = respXML.getElementsByTagName("id");
	var rLAT = respXML.getElementsByTagName("lat");
	var rLGT = respXML.getElementsByTagName("lgt");
	
	// ... and use it as needed by your app.
	//alert(r2);
	for (var i=0;i<rID.length;i++)
		  {
		  var id=rID[i].childNodes[0].nodeValue;
		  var lat=rLAT[i].childNodes[0].nodeValue;
		  var lgt=rLGT[i].childNodes[0].nodeValue;
		  
		  dodajMarker(id,lat,lgt);
		  }
	setTimeout(dajVozilo,5000);  
	return;
	};
	req.open("GET","korisno/Avozilo/AKoo?id="+koje, true);
	req.send();
}

function dodajMarker(id,lat,lgt) {
	  var image="slike/bus-ticket-icon.png";
	  var marker = new google.maps.Marker({
	    position: new google.maps.LatLng(lat,lgt),
	    map: map,
	    id: id,
	    icon: image,
	    
	  });
	  
	  markers.push(marker);
	}